﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using EPiServer.Core;

namespace EPiSugar.Navigation
{
    public class EnumerationAppender
    {
        private readonly IEnumerable<PageData> pages;

        public EnumerationAppender(IEnumerable<PageData> pages)
        {
            this.pages = pages;
        }

        public IEnumerable<PageData> Children()
        {
            foreach (var page in pages)
            {
                yield return page;
                foreach (var child in page.Children())
                {
                    yield return child;
                }
            }
        }

        public IEnumerable<PageData> Parents()
        {
            foreach (var page in pages)
            {
                yield return page;
                yield return page.Parent();
            }
        }

        public IEnumerable<PageData> Descendants()
        {
            return Descendants(int.MaxValue);
        }

        public IEnumerable<PageData> Descendants(int recursionDepth)
        {
            foreach (var page in pages)
            {
                yield return page;
                foreach (var descendant in page.Descendants(recursionDepth))
                {
                    yield return descendant;
                }
            }
        }
    }
}
